﻿using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using TodoList.Data;

namespace TodoList.FastEndpoints.Features.GetList;

internal sealed class Endpoint(ApplicationDbContext db) : Endpoint<EmptyRequest, Response>
{
    public override void Configure()
    {
        Get("/api/todoList");
        AllowAnonymous();
    }

    public override async Task HandleAsync(EmptyRequest r, CancellationToken c)
    {
	    var todos = await db.TodoItems.ToListAsync(c);
	    await SendAsync(new Response { TodoItems = todos }, cancellation: c);
    }
}
